export default {
  data() {
    return {}
  },
  methods: {
    /**
     * 画区域(多边形)
     * @param options {Object}
     */
    drawMapPolygonArea(options) {
      let {layerId = '', lists = [], item = {}} = options
      if (!layerId) {
        return console.log('%c请传入layerId！', 'color:red;')
      }
      if (!lists.length) {
        return false;
      }

      let currentLayer = this.gisIns.getLayer(layerId)
      if (!currentLayer) {
        currentLayer = this.gisIns.createVector({zIndex: 108}, layerId)
      }
      let layerSource = currentLayer.getSource()
      // if (datas.clearOwnLayer) {
      //   layerSource.clear()
      // }

      let areaFeature = this.gisIns.addPolygon(currentLayer, lists)
      areaFeature.setId(item.id || '')
      areaFeature.set('name', item.name || '')
    },
    /**
     * 画区域(圆形)
     * @param layerid {String} 图层id
     * @param center {Object} 中心点 {lng,lat}
     * @param radius {String} 区域的唯一id
     * @param id {String} 区域的唯一id
     * @param name {String} 区域名称
     */
    drawMapCircle({layerid, center, radius, id, name}) {
      let CircleFeature = this.gisIns.addCircle(this.gisIns.getLayer(layerid), {
        center: center,
        radius: this.gisIns.meterToRadiusDegrees(radius),
      })
      CircleFeature.setId(id)
      CircleFeature.set('name', name)
      // if (center) {
      //   this.map.getView().animate({
      //     // 只设置需要的属性即可
      //     // 中心点
      //     center: this.gisIns.transform(center[0], center[1]),
      //     // zoom: 12, // 缩放级别
      //     duration: 300 // 缩放持续时间，默认不需要设置
      //   })
      // }
    },
    /**
     * 根据图层和id删除Feature
     * @param layerid {String} 图层id
     * @param id {String} 区域的唯一id
     */
    delMapFeature({layerid, id}) {
      let arealayer = this.gisIns.getLayer(layerid)
      let areaSource = arealayer.getSource()
      let areaFeature = areaSource.getFeatureById(id)
      if (areaFeature) {
        areaSource.removeFeature(areaFeature);
      }
    }
  }
}
